package com.play.ballen.home.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.luck.picture.lib.photoview.PhotoView;
import com.play.ballen.R;
import com.youth.banner.Banner;
import com.youth.banner.adapter.BannerAdapter;
import com.yuven.appframework.util.imageloader.ImageUtil;

import java.util.List;

public class ScanAdapter extends BannerAdapter<String,RecyclerView.ViewHolder> {
    private Context context;
    private Banner banner;

    public ScanAdapter(Context context, List datas) {
        super(datas);
        this.context=context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.item_banner_scan_img,parent,false);
        return new ImgViewHolder(view);
    }

    @Override
    public void onBindView(RecyclerView.ViewHolder holder, String data, int position, int size) {
        ((ImgViewHolder)holder).bindData(data);
    }
    class ImgViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        private PhotoView photoView;
        public ImgViewHolder(@NonNull View itemView) {
            super(itemView);
            photoView=itemView.findViewById(R.id.photo_view);
            photoView.setOnClickListener(this);
        }
        public void bindData(String media){
            ImageUtil.Companion.getInstance().loadImage(media,photoView);
        }

        @Override
        public void onClick(View v) {
            if (context instanceof Activity){
                ((Activity)context).finish();
            }
        }
    }
}
